package org.example.day08;

/**
 * 第三章节3.1.15.1: 方法wait(long)的基本使用
 *      作用:主动释放锁，在时间内被唤醒，如果未在时间内被唤醒，则自动唤醒.
 */
public class MyThread {
    private static Object lock = new Object();
    private static Runnable runnable1 = new Runnable() {
        @Override
        public void run() {
            try {
                synchronized (lock){
                    System.out.println("wait begin time = " + System.currentTimeMillis());
                    lock.wait(5000); //5s内不被唤醒会自动唤醒
                    System.out.println("wait end time = " + System.currentTimeMillis());
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };

    public static void main(String[] args) {
        Thread t = new Thread(runnable1);
        t.start();
    }
}
